const urlDao = require('../dao/urlDao'),
  uwDao = require('../dao/urlWordDao'),
  log = require('../util/log');

exports.start = () => {
  require('../util/zoroDB').query('select url from url group by url having count(*)>1', [], (err, rows, fields) => {
    if (err) {
      log(err)
      return
    }
    rows.forEach(row => {
      urlDao.select({
        url: row.url
      }, urls => {
        for (var i = 1; i < urls.length; i++) {
          var url = urls[i]
          log('删除了[' + url.id + ']' + url.url)
          urlDao.delete(url.id)
          uwDao.deleteByUrlId(url.id)
        }
      })
    })
  })
}
